//路由鉴权
import router from "@/router";
import {useUserInfoStore} from "@/stores/user_info";
import {childrenRouter} from "@/router/router";

let userInfoStore: any = null;
//全局前置守卫
router.beforeEach(async (to: any, from: any, next: any) => {
    document.title = "小鸡毛网盘 - " + to.meta.title

    if (to.path == "/external-sharing" || to.path.startsWith("/verify/") || to.path.startsWith("/s/")) {
        next()
        return
    }
    //引入用户缓存信息
    if (userInfoStore == null) {
        userInfoStore = useUserInfoStore()
    }
    if (userInfoStore.token) {

        // 登录后跳转到登录页和注册页直接重定向到首页
        if (to.path == "/login" || to.path == "/register") {
            next('/')
            return
        }
        next()

    } else {
        if (to.path == '/login' || to.path == '/register') {
            next()
        } else {
            next({path: '/login', query: {redirect: to.path}})
        }
    }
})
//全局后置守卫
router.afterEach((to: any, from: any) => {

})
